/**
 * @author yz
 */

PreviewPanel = function(config){
	
	config.bodyStyle = "padding:5px;";
	
	PreviewPanel.superclass.constructor.call(this,config);
	
	this.content = config.content||"";

	var iframe = this.iframe = document.createElement('IFRAME');
		
	iframe.style.height = "100%";
	
	iframe.style.width = "100%";
	
	iframe.frameBorder = 0;

}

Ext.extend(PreviewPanel,Ext.Panel,{
	
	afterRender : function(){
		
		PreviewPanel.superclass.afterRender.call(this);
				
		this.body.appendChild(this.iframe);
		
		this.updateContent(this.content);
	
	},
	
	updateContent : function(newcontent){
		
		var html = ["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/><title>Preview</title></head><body style=\"margin:0px\">"];
		
		html.push(newcontent);
		
		html.push("</body></html>");
		
		var doc = this.iframe.contentWindow.document;
		
		doc.open();
		
		doc.write(html.join(""));
		
		doc.close();
		
	},
	
	lazyUpdateContent:function(newcontent){
		if (newcontent != this.content) {
			this.content = newcontent;
			this.updateContent(newcontent);
		}
	}
	
});

Ext.reg("mashuproom.previewpanel",PreviewPanel);
